package com.service.impl;

import com.dao.UserDao;
import com.dao.impl.UserDaoImpl;
import com.pojo.User;
import com.service.UserService;
import com.util.LayuiTable;

import java.util.List;

public class UserServiceImpl implements UserService {

    UserDao userDao = new UserDaoImpl();

    @Override
    public User findUser(User user) {


        return  userDao.getuserOne(user);
    }

    @Override
    public User findUser(int id) {
        return userDao.getuserOne(id);
    }

    @Override
    public LayuiTable<User> findAll(int page,int limit) {
        LayuiTable<User> userLayuiTable = new LayuiTable<User>();

        int cruentPage=(page-1)*limit;

        List<User> userList = userDao.getuserAll(cruentPage,limit);
        userLayuiTable.setMsg("");
        userLayuiTable.setCode(0);
        userLayuiTable.setCount(userDao.getuserAll().size());
        userLayuiTable.setData(userList);
        return userLayuiTable;
    }

    @Override
    public int delUserById(int id) {
       try {
           int i = userDao.delUser(id);
           return i;
       }catch (Exception e){
           e.printStackTrace();
       }
        return -1;
    }

    @Override
    public int doUpadateUser(User user) {
        try {
            int i = userDao.upateUser(user);
            return i;
        }catch (Exception e){
            e.printStackTrace();
        }
        return -1;
    }

    @Override
    public int addUser(User user) {
        try {
            int i = userDao.insertUser(user);
            return i;
        }catch (Exception e){
            e.printStackTrace();
        }
        return -1;
    }
}
